package com.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.mapper.Sms_Spu_Bounds_Mapper;
import com.shop.service.Sms_Spu_Bounds_Service;
import com.shop.pojo.sms.Sms_Spu_Bounds;
import com.shop.to.SpuByBoundsTo;
import com.shop.utils.LayuiUtils;
import com.shop.utils.R;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
//商品spu积分设置业务层
@Service
public class Sms_Spu_Bounds_ServiceImpl extends ServiceImpl<Sms_Spu_Bounds_Mapper, Sms_Spu_Bounds> implements Sms_Spu_Bounds_Service {


    @Autowired
    private Sms_Spu_Bounds_Mapper sms_spu_bounds_mapper;

    /*
     * @Description 添加一条spu积分设置
     * @param spuByBoundsTo
     * @return com.shop.utils.R
     * @author liusupeng
     * @date 2020/11/6 8:54
     */
    @Override
    public R saveBoundsBySpu(SpuByBoundsTo spuByBoundsTo) {
              Sms_Spu_Bounds sms_spu_bounds=new Sms_Spu_Bounds();
        BeanUtils.copyProperties(spuByBoundsTo,sms_spu_bounds);//将SpuByBoundsTo的值传入到sms_spu_bounds对象里
        boolean save = this.save(sms_spu_bounds);
        if(save){
            return R.success();
        }
        return R.error(500,"数据库异常");
    }

    /**
     * 后台显示所有商品spu积分
     * @param pages
     * @param sms_spu_bounds
     * @return
     */
    @Override
    public LayuiUtils<Sms_Spu_Bounds> find_admin_sms_spu_bounds(Page<Sms_Spu_Bounds> pages, Sms_Spu_Bounds sms_spu_bounds) {
        LayuiUtils<Sms_Spu_Bounds> layuiUtils = new LayuiUtils<>();
        QueryWrapper<Sms_Spu_Bounds> queryWrapper = new QueryWrapper<>();
        if (sms_spu_bounds.getSpu_id() != null){
            queryWrapper.eq("spu_id",sms_spu_bounds.getSpu_id());
        }
        Page<Sms_Spu_Bounds> sms_spu_boundsPage = sms_spu_bounds_mapper.selectPage(pages,queryWrapper);
        layuiUtils.setCount(sms_spu_boundsPage.getTotal());
        layuiUtils.setData(sms_spu_boundsPage.getRecords());
        return layuiUtils;
    }


}
